Rails.application.routes.draw do
  mount Ckeditor::Engine => '/ckeditor'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

  namespace :cip, path: nil do
    namespace :admin do
      resource :user
      resource :user_session

      resources :pages
      resources :categories do
        resources :categories
        resources :pages do
          post :reorder, on: :collection
        end
      end

      resource :faq

      root to: 'pages#index'
    end

    resources :pages, only: [:index, :show]
    get 'categories/:category_id' => 'pages#category', as: :category
    get 'categories/:category_id/page' => 'pages#category_page', as: :category_page
    get 'categories/:category_id/first_child' => 'pages#category_first_child', as: :category_first_child
    get 'static/:page_id' => 'pages#static', as: :static
  end

  namespace :ssp do
    resource :user_session

    resources :users
    resource :user, controller: :current_users, as: :current_user

    resources :reports do
      member do
        post :confirm
        post :reject
      end

      collection do
        get 'batch/:ids/confirm' => 'reports#batch_confirm', as: :batch_confirm
        get 'batch/:ids/reject' => 'reports#batch_reject', as: :batch_reject
        get 'batch/:ids/destroy' => 'reports#batch_destroy', as: :batch_destroy
      end
    end

    resource :faq

    root to: 'reports#index'
  end

  get ':slug/faq' => 'faqs#show', as: :faq

  if ENV.include? 'WEBSITE_SSP_ONLY'
    root to: 'ssp/reports#index'
  else
    root to: 'cip/pages#index'
  end
end
